package com.ftg.learn.entity;

import com.ftg.learn.entity.primary.A;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author kangjx
 * @createTime 2022/8/11
 */
public class Play {

    //控制转移 ： 将类的生命周期创建权限全部移将spring  ioc

    //spring ioc 容器[存储类的实例（对象） 单例 原型 ]

    /**
     * 到spring容器里面自动拿到A 的实现类的实例 a2
     */
    @Autowired
    @Qualifier("cimpl")
    A a2;

    public static void main(String[] args) {
        //安装容器
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring.xml");
        A a1 = (A) beanFactory.getBean("bimpl");
        a1.test1();
        A a2 = (A) beanFactory.getBean("cimpl");
        a2.test1();

    }

}
